# Maintainer: Biswapriyo Nath <nathbapai@gmail.com>

_realname=duktape
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7.0
pkgrel=1
pkgdesc='Embeddable Javascript engine (mingw-w64)'
url='https://duktape.org/'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("http://duktape.org/duktape-${pkgver}.tar.xz"
        "duktape.pc")
sha256sums=('90f8d2fa8b5567c6899830ddef2c03f3c27960b11aca222fa17aa7ac613c2890'
            '1a411ea5ff234f28aeb0c891650e96fd75360696cdaf6a049c73c081a558f84c')

prepare() {
  sed -i "s|@PREFIX@|${MINGW_PREFIX}|g" duktape.pc
  sed -i "s|@VERSION@|${pkgver}|g" duktape.pc
}

build() {
  cd "${_realname}-${pkgver}"
  ${CC} src/duktape.c ${CPPFLAGS} ${CFLAGS} -c -o duktape.o
  ar rcs libduktape.a duktape.o
}

package() {
  cd "${_realname}-${pkgver}"
  install -Dm644 "src/duk_config.h" "${pkgdir}${MINGW_PREFIX}/include/duk_config.h"
  install -Dm644 "src/duktape.h" "${pkgdir}${MINGW_PREFIX}/include/duktape.h"
  install -Dm644 "libduktape.a" "${pkgdir}${MINGW_PREFIX}/lib/libduktape.a"
  install -Dm644 "${srcdir}/duktape.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/duktape.pc"
  install -Dm644 "LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
